package com.chushouya.manager.dao.repository;

import com.chushouya.manager.dao.entity.UserRoleEntity;
import com.chushouya.manager.dao.mapper.UserRoleEntityMapper;
import com.general.framework.data.mybatis.BaseRepository;
import org.springframework.stereotype.Repository;
import tk.mybatis.mapper.entity.Example;

import java.util.List;

@Repository
public class UserRoleRepository extends BaseRepository<UserRoleEntityMapper, UserRoleEntity, Long> {

    public void deleteUserRole(Long adminUserId) {
        Example example = this.buildExample();
        example.and().andEqualTo("adminUserId", adminUserId);
        this.deleteByExample(example);
    }

    public List<UserRoleEntity> selectUserRoleByRoleId(Long roleId) {
        Example example = this.buildExample();
        example.and().andEqualTo("roleId", roleId);
        return this.selectByExample(example);
    }

    public List<UserRoleEntity> selectUserRole(Long adminUserId) {
        Example example = this.buildExample();
        example.and().andEqualTo("adminUserId", adminUserId);
        return this.selectByExample(example);
    }

    public void deleteUserRole(Long roleId, List<Long> adminUserIdList) {
        Example example = this.buildExample();
        example.and().andEqualTo("roleId", roleId);
        example.and().andIn("adminUserId", adminUserIdList);
        this.deleteByExample(example);
    }
}
